A hydraulic excavator, which is one of work machines, includes: a carrier; an upper revolving unit disposed on the carrier and capable of revolving; and a work implement disposed on the upper revolving unit. The work implement includes: a boom having one end pivotably supported on a base body portion; an arm having one end pivotably supported on the other end of the boom; and an attachment pivotably supported on the other end of the arm. The boom, the arm, and the attachment are driven by hydraulic cylinders. In order to detect the position and posture of this work implement, a stroke of each hydraulic cylinder is measured.
For example, Japanese Patent Laying-Open No. 2006-258730 (Patent Document 1) discloses a hydraulic excavator including a position sensor that detects a piston stroke position of a hydraulic cylinder, which drives a work implement, by means of rotation of a rotary roller on a cylinder rod thereof. Slight slippage between the rotary roller and the cylinder rod introduces an error between an actual stroke position and a stroke position obtained from a result of detection of the position sensor. In order to calibrate the stroke position obtained from the result of detection of the position sensor in accordance with a reference position, a magnetic force sensor serving as a reset sensor is provided at the reference position on the external surface of the cylinder tube of the hydraulic cylinder. Whenever the piston passes through the reference position during work, a stroke position detected by the position sensor is calibrated, thereby attaining precise position measurement.